package com.butuh.uang.tuh.ang.ui;

import android.os.Bundle;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.butuh.uang.tuh.ang.R;
import com.butuh.uang.tuh.ang.present.PYinSi;
import com.butuh.uang.tuh.ang.util.OnClickLogUtils;

import butterknife.BindView;
import butterknife.OnClick;
import cn.droidlover.xdroidmvp.mvp.XActivity;

public class YinSiActivity extends XActivity<PYinSi> {

    @BindView(R.id.tv_message)
    TextView mTvMessage;

    @BindView(R.id.layout_no_net)
    LinearLayout mLayoutNoNet;
    @BindView(R.id.layout_error)
    LinearLayout mLayoutError;
    @BindView(R.id.tv_error_message)
    TextView mTvErrorMessage;
    String yemianName = "KebijakanPrivasi";

    @Override
    public void initData(Bundle savedInstanceState) {
        OnClickLogUtils.onClickLog(this, "come-in-into", "[\\\"KebijakanPrivasi\\\"]", 0);
        mDialog.Show();
        getP().getYinSi();
    }


    public void loadSuccess(String message) {
        mDialog.Dismiss();
        if (!TextUtils.isEmpty(message)) {
            mTvMessage.setVisibility(View.VISIBLE);
            mLayoutNoNet.setVisibility(View.GONE);
            mLayoutError.setVisibility(View.GONE);
            mTvMessage.setText(Html.fromHtml(message));
        } else {
            mTvMessage.setVisibility(View.GONE);
            mLayoutNoNet.setVisibility(View.GONE);
            mLayoutError.setVisibility(View.VISIBLE);
            mTvErrorMessage.setText("Saat ini tidak ada produk");
        }
    }


    public void loadError(int type, String message) {
        mDialog.Dismiss();
        if (type == 1) {
            mTvMessage.setVisibility(View.GONE);
            mLayoutNoNet.setVisibility(View.VISIBLE);
            mLayoutError.setVisibility(View.GONE);
        } else {
            mTvMessage.setVisibility(View.GONE);
            mLayoutNoNet.setVisibility(View.GONE);
            mLayoutError.setVisibility(View.VISIBLE);
            mTvErrorMessage.setText(message);
        }
    }


    @OnClick({R.id.iv_back, R.id.tv_resume})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                OnClickLogUtils.onClickPermute(context, yemianName, "back", 0);
                break;
            case R.id.tv_resume:
                mDialog.Show();
                getP().getYinSi();
                OnClickLogUtils.onClickPermute(context, yemianName, "errorResume", 0);
                break;
        }
    }


    @Override
    public int getLayoutId() {
        return R.layout.activity_yinsi;
    }

    @Override
    public PYinSi newP() {
        return new PYinSi();
    }
}
